import type { PayloadAction } from "@reduxjs/toolkit";

import { createAppSlice } from "../utils";
import { RootState } from "../store";

export interface CounterSliceState {
  value: string;
  status: "idle" | "loading" | "failed";
}

const initialState: CounterSliceState = {
  value: "小明",
  status: "idle",
};

export const userSlice = createAppSlice({
  name: "userStore",
  initialState,
  reducers: (create) => ({
    setValue: create.reducer((state, action: PayloadAction<string>) => {
      state.value = action.payload;
      console.log("payload", action);
    }),
  }),
  selectors: {
    selectCount: (state) => state.value,
  },
});
export const { setValue } = userSlice.actions;
export const value = (state: RootState) => {
  return state.userStore.value;
};

export const { selectCount } = userSlice.selectors;
